using System.Collections.Generic;

namespace Grapher
{
    public class AddOns : List<AddOn>
    {
        public AddOns(AddOn chartType)
        {
            AddAfterChecking(chartType);
        }

        public AddOns()
        {
        }

        public string Urify()
        {
            var result = string.Empty;
            if (Count == 0) return result;

            foreach (var addOn in this)
            {
                result += addOn.Urify() + "&";
            }
            return result.Substring(0, result.Length - 1);
        }

        public void AddAfterChecking(AddOn addOn)
        {
            if (Exists(addon => addon.GetType().Equals(addOn.GetType())))
                throw new DuplicateAddOnException(addOn.GetType());
            Add(addOn);
        }

        public ChartType FindChartType()
        {
            return (ChartType) Find(addOn => addOn.GetType().Equals(typeof (ChartType)));
        }
    }
}